import java.util.*;
public class Test {
    //输入集合A及在A上的二元关系R，判断二元关系R的几种基本性质。
    //要求：能正确判定任意二元关系的自反性、对称性、传递性、反自反性和反对称性
    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        System.out.println("请输入集合A中元素个数:");
        int n = in.nextInt();

        int[][] val = new int[n][n];
        System.out.println("请输入集合A上的二元关系R的关系矩阵:");
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                val[i][j] = in.nextInt();
                if(val[i][j] != 1 && val[i][j] != 0){
                    System.out.println("输入有误，关系矩阵中的元素只能为1或0！");
                    return;
                }
            }
        }

        if(judgeRef(val, n)){
            System.out.println("R满足自反性");
        }else{
            System.out.println("R不满足自反性");
        }

        if(judgeSym(val, n)){
            System.out.println("R满足对称性");
        }else{
            System.out.println("R不满足对称性");
        }

        if(judgeTran(val, n)){
            System.out.println("R满足传递性");
        }else{
            System.out.println("R不满足传递性");
        }

        if(judgeAntiRef(val, n)){
            System.out.println("R满足反自反性");
        }else{
            System.out.println("R不满足反自反性");
        }

        if(judgeAntiSym(val, n)){
            System.out.println("R满足反对称性");
        }else{
            System.out.println("R不满足反对称性");
        }
    }
    //判断二元关系R是否满足自反性
    public static boolean judgeRef(int[][] val, int n){
        boolean ret = true;
        for (int i = 0; i < n; i++) {
            if(val[i][i] != 1){
                ret = false;
                break;
            }
        }
        return ret;
    }

    //判断二元关系R是否满足对称性
    public static boolean judgeSym(int[][] val, int n){
        boolean ret = true;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if(val[i][j] != val[j][i]){
                    ret = false;
                    break;
                }
            }
        }
        return ret;
    }

    //判断二元关系R是否满足传递性
    public static boolean judgeTran(int[][] val, int n){
        boolean ret = true;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if(val[i][j] == 1) {
                    for (int k = 0; k < n; k++) {
                        if (val[j][k] == 1 && val[i][k] == 0) {
                            ret = false;
                            break;
                        }
                    }
                }
            }
        }
        return ret;
    }

    //判断二元关系R是否满足反自反性
    public static boolean judgeAntiRef(int[][] val, int n){
        boolean ret = true;
        for (int i = 0; i < n; i++) {
            if(val[i][i] == 1){
                ret = false;
                break;
            }
        }
        return ret;
    }

    //判断二元关系R是否满足反对称性
    public static boolean judgeAntiSym(int[][] val, int n){
        boolean ret = true;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if(val[i][j] == 1 && val[j][i] == 1 && i != j){
                    ret = false;
                    break;
                }
            }
        }
        return ret;
    }
}
